import React, { Component } from 'react';
import {
  StyleSheet,
  Text,
  View,
  ScrollView,
  Image,
  TextInput,
  TouchableOpacity,
  ToastAndroid,
  Platform,
  DeviceEventEmitter,
  InteractionManager,
  NativeAppEventEmitter,
  Dimensions
} from 'react-native';

import * as config from '../../constants/apiConfig';
import styles from './editOrderStyle';
import DatePicker from 'react-native-datepicker';
import moment from 'moment';
import api from '../../services/api';
import helper from '../util/helper';
import { Navigation } from '../global/navigation/index';

import Toast from 'react-native-sk-toast';
import ToastTip from '../global/ToastTip';
import LoadingTip from '../global/LoadingTip';
import Touch from '../global/Touch';
import ImagePicker from 'react-native-image-picker';
import DeviceStorage from '../global/DeviceStorage';

import KeyboardAwareScrollView from '../global/keyboardScrollView/KeyboardAwareScrollView';
import dismissKeyboard from 'dismissKeyboard';

const SAVE_ORDER_KEY = "@order@send";
const {width: deviceWidth, height: deviceHeight} = Dimensions.get('window');
class EditSendOrder extends Component {
    constructor(props) {
		super(props);

        let {data, source} = props;

        let act = [0,0];
        if(source == 'edit'){
            if(data.isThirdParty == 1){
                act[1] = 1;
            }else{
                act[0] = 1;
            }
        }else{
            act = [1,0];
        }

		this.state = {
            loadingShow: false,
			isRefreshing: false,
			currentPage: 1,
            addrContent: false,
            roomInfo: false,
            roomLocation: false,
            date: source=='edit'?moment(data.service_time).format('YYYY-MM-DD HH:mm'):moment().add(30,'minutes').format('YYYY-MM-DD HH:mm'),
            list:{},
            send_phone: source=='edit'?data.user_phone:(this.props.userPhone?this.props.userPhone:''),
            remarks:source=='edit'?(data.remarks||''):'',
            weixin: source=='edit'?data.weixin:'',
            send_address: source=='edit'?data.from_address: '',
            receive_address: source=='edit'?data.to_address: '',

            start_location: source=='edit'?data.start_location: '',
            dest_location: source=='edit'?data.dest_location: '',
            activeServiceWay:act,
            disableUpload:false,
            orderCreateSuccess:false,
		};

        // AndroidKeyboardAdjust.setAdjustResize();

		// this.props.navigator.setOnNavigatorEvent(this._onNavigatorEvent.bind(this));
	}

    _addAddress(type){
        let title = '';
        let address = '';
        let location = '';
        let {data, source} = this.props;
        let {send_address, receive_address, start_location, dest_location, addrContent, roomInfo, roomLocation} = this.state;

        switch(type){
            case 'send':
                title = '填写寄出地址';
                address = send_address;
                location = start_location;
                break;
            case 'receive':
                title = '填写收货地址';
                address = receive_address;
                location = dest_location;
                break;
        }

        this.props.navigator.push({
            title: title,
			screen: 'housekeeperapp.editaddress',
            backButtonTitle:'',
			passProps: {
				// orderId
                type,
                tab:'send',
                address_store: address,
                location_store: location,
                addrContent,
                roomInfo,
                roomLocation
			},
            navigatorStyle:{
                tabBarHidden: true,
                navBarTextColor: 'white',
            	navBarButtonColor: 'white',
            	navBarBackgroundColor: '#EA5404',
                statusBarColor: '#EA5404',
                navBarTitleTextCentered: true,
                topBarElevationShadowEnabled:false
            },
            navigatorButtons:{
                leftButtons:[
                    {
                        id: 'back',
                        icon: require("../../../img/hk_back_icon.png")
                    }
                ],
                rightButtons:[
                    {
                        title:'选择城市',
                        id: 'city',
                        component: 'housekeeperapp.editaddrrightbtn',
                        passProps: {
                            text: '选择城市',
                        },
                    }
                ]
            }
		});
    }

    async _getServiceFeeInfo(phone,date){
        let res = await api.post('/order/serviceFee',{phone:phone,service_type:'send',serviceTime:date+":00",otherServiceType:''});
        if (res.cd != 0) {
            return;
        }
        if (res.data) {
            if (res.data.isPay) {//有服务费
                let serviceFee = res.data.serviceFee;
                let totalServiceFee = 0;
                serviceFee.map((item,index) => {
                   totalServiceFee += parseFloat(item.fee);
                })
                this.setState({
                    isPay:res.data.isPay,
                    serviceFee,
                    totalServiceFee,
                })
            }else{
                this.setState({
                    isPay:res.data.isPay,
                    serviceFee:[],
                    totalServiceFee:0,
                })
            }
        }else{
            this.refs.toast.show('获取服务费数据失败'+res.msg)
            this.setState({
                    isPay:false,
                    serviceFee:[],
                    totalServiceFee:0,
                })
        }
        

    }

    _serviceFeeExplain(serviceFeeInfo){
        let {date,send_phone} = this.state;
        Navigation.startServiceFeeExplain({'selectedDate':date+":00",'phone':send_phone,"serviceFeeName":serviceFeeInfo.serviceFeeName,"groupId":serviceFeeInfo.groupId});
    }

    async _submitAction(){
        // let {send_address, receive_address} = this.props.order;
        let {source, data, order} = this.props;

        let {date, weixin, send_phone, receive_phone, obj_name, remarks, send_address, receive_address, start_location, dest_location, activeServiceWay,fileUri,fileData,ownerInfo} = this.state;
        let req_data = {
            from_address: send_address,
            to_address: receive_address,
            buy_address: '',
            service_type: 'send',
            service_time: date||(source=='edit'?data.service_time:''),
            obj_name: obj_name||(source=='edit'?data.obj_name:''),
            obj_price: 0,
            phone: receive_phone||(source=='edit'?data.phone:''),
            user_phone: send_phone,
            remarks: remarks,
            express_service_content:'',
            lockkey_service_content:'',
            other_service_content:'',
            obj_image:'',
            start_location:start_location,
            dest_location:dest_location,
            weixin: weixin,
            thirdPartyName: source=='edit'?(data.thirdPartyName||''):'',
            thirdPartyPerson: source=='edit'?(data.thirdPartyPerson||''):'',
            thirdPartyPhone: source=='edit'?(data.thirdPartyPhone||''):'',
            ownerInfo:ownerInfo,
        };

        if(source == 'edit'){
            req_data.id = data.id;
        }else{//创建时
            req_data.status = 1;
        }

        if(!req_data.user_phone){
            this.refs.toast.show('请输入发件人手机号码');
            return;
        }
        if(!req_data.phone){
            this.refs.toast.show('请输入收件人手机号码');
            return;
        }

        if(!/^1[0-9]{10}$/.test(req_data.user_phone)){
            this.refs.toast.show('请输入正确的发件人手机号码');
            return;
        }

        if(!/^1[0-9]{10}$/.test(req_data.phone)){
            this.refs.toast.show('请输入正确的收件人手机号码');
            return;
        }

        if(!req_data.from_address){
            this.refs.toast.show('请输入寄出地址');
            return;
        }
        if(!req_data.to_address){
            this.refs.toast.show('请输入收货地址');
            return;
        }

        // if(!req_data.weixin){
        //     this.refs.toast.show('请输入发件人微信号');
        //     return;
        // }
        //
        // if(req_data.weixin.length>16){
        //     this.refs.toast.show('发件人微信号不能超过16个字符');
        //     return;
        // }


        if(!req_data.obj_name){
            this.refs.toast.show('请输入物品名称');
            return;
        }

        if(req_data.obj_name.length>100){
            this.refs.toast.show('物品名称不能超过100个字符');
            return;
        }

        if(moment(req_data.service_time)-moment()<0){
            this.refs.toast.show('输入的时间需大于当前时间');
            return;
        }

        if(req_data.remarks.length>200){
            this.refs.toast.show('备注信息不能超过200个字符');
            return;
        }

        if(activeServiceWay[1] == 1){
            this.props.navigator.push({
                title: source=='edit'?"编辑服务方":"填写服务方",
    			screen: 'housekeeperapp.editserviceside',
                backButtonTitle:'',
    			passProps: {
                    order_phone: this.props.userPhone,
                    source: source,
                    data: req_data,
                    fileUri:this.state.fileUri,
                    isPay:this.state.isPay,
                    serviceFee:this.state.serviceFee,
    			},
                navigatorStyle:{
                    tabBarHidden: true,
                    navBarTextColor: 'white',
                	navBarButtonColor: 'white',
                    statusBarColor: '#EA5404',
                	navBarBackgroundColor: '#EA5404',
                    navBarTitleTextCentered: true,
                    topBarElevationShadowEnabled:false
                },
                navigatorButtons: {
                    leftButtons:[
                        {
                            id: 'back',
                            icon: require("../../../img/hk_back_icon.png")
                        }
                    ]
                }
    		});
            return;
        }

        if(source != 'edit'){
            this.props.navigator.push({
                title: "确认提交订单",
    			screen: 'housekeeperapp.orderconfirm',
                backButtonTitle:'',
    			passProps: {
    				order_detail:req_data,
                    order_phone: this.props.userPhone,
                    fileUri:this.state.fileUri,
                    isPay:this.state.isPay,
                    serviceFee:this.state.serviceFee,
    			},
                navigatorStyle:{
                    tabBarHidden: true,
                    navBarTextColor: 'white',
                	navBarButtonColor: 'white',
                	navBarBackgroundColor: '#EA5404',
                    statusBarColor: '#EA5404',
                    navBarTitleTextCentered: true,
                    topBarElevationShadowEnabled:false
                },
                navigatorButtons: {
                    leftButtons:[
                        {
                            id: 'back',
                            icon: require("../../../img/hk_back_icon.png")
                        }
                    ]
                }
    		});
            return;
        }

        this.setState({loadingShow:true});
        req_data = {...req_data,remarkImage:fileData?fileData:''};
        // let url = (source == 'edit'? :'/order/createorder');
        let res = await api.post('/order/updateorder',req_data);
        if(res.cd == 1){
            this.setState({
                loadingShow:false
            },() =>{
                this.refs.toast.show(res.msg);
            })
            
        }else{
            if(res.data){
                this.setState({loadingShow:false});
                Toast.bottom("编辑成功");
                setTimeout(()=>{
                    this.props.navigator.pop();
                    let Emitter = Platform.OS === 'android' ? DeviceEventEmitter : NativeAppEventEmitter;
                    Emitter.emit("order.onload");
                }, 500);
            }
        }

    }

    async _showUserAddrBtn(text){
        let phone = text || this.state.send_phone;

        if(phone){
            let res = await api.post('/account/findUserByPhone',{phone});
            if(res && res.data){
                let roomRes = await api.post('/account/findRoomInfoById',{id:res.data.roomId});
                if(roomRes && roomRes.data){
                    this.setState({
                        addrContent:roomRes.data.city+roomRes.data.homeNeighbourhoods,
                        roomInfo:roomRes.data.homeBuilding+roomRes.data.homeUnit+roomRes.data.roomNo,
                        roomLocation: roomRes.data.roomLocation,
                        ownerInfo:res.data
                    });
                }else{
                    this.setState({
                        addrContent:res.data.homeAddress,
                        ownerInfo:res.data
                    });
                }
            }else{
                this.setState({
                    addrContent:res.data.homeAddress,
                    ownerInfo:res.data
                });
            }
        }
    }

    componentDidMount(){
        let Emitter = Platform.OS === 'android' ? DeviceEventEmitter : NativeAppEventEmitter;
        this._subcribOrder = Emitter.addListener('order.create_success', this._orderCreateSuccess.bind(this));
    }

    _orderCreateSuccess(){
        this.setState({
            orderCreateSuccess:true,
        })
    }

    componentWillMount(){
        let {source} = this.props;
        if(source == 'edit'){
            return;
        }
        
        let {send_phone,date} = this.state;
        if (send_phone && date) {
            this._getServiceFeeInfo(send_phone,date);
        }

        DeviceStorage.get(SAVE_ORDER_KEY).then((origin_data)=>{
            if(origin_data){
                let story = this.props.userPhone?Object.assign({},origin_data,{send_phone: this.props.userPhone}):origin_data;
                this.setState(story);
            }
            this._showUserAddrBtn();
        });
    }

    componentWillUnmount(){
        let {source} = this.props;
        let {date, send_phone, receive_phone, obj_name, remarks, send_address, receive_address, start_location, dest_location} = this.state;
        let restory;
        if(this.props.userPhone){
            restory = { receive_phone, obj_name, remarks, send_address, receive_address, start_location, dest_location};
        }else{
            restory = { send_phone, receive_phone, obj_name, remarks, send_address, receive_address, start_location, dest_location};
        }

        source!='edit' && !this.state.orderCreateSuccess && DeviceStorage.save(SAVE_ORDER_KEY, restory);
        this._subcribOrder && this._subcribOrder.remove();
    }

    async clearContent(){

        // this.setState({loadingShow:true}, ()=>{
        //     InteractionManager.runAfterInteractions(() => {
        //         setTimeout(async()=>{
        //             let {actions, dispatch} = this.props;
        //             let action;
        //             action = actions.order.order_clearaddress();
        //             await dispatch(action);
        //         }, 100);
        //     });
        // });
        let {actions, dispatch} = this.props;
        let action;
        action = actions.order.order_clearaddress();
        await dispatch(action);

        this.setState({
            date: moment().add(30,'minutes').format('YYYY-MM-DD HH:mm'),
            send_phone:'',
            receive_phone:'',
            obj_name:'',
            remarks:'',
            loadingShow:false,
            send_address: '',
            receive_address: '',
            start_location:'',
            dest_location:'',
            activeServiceWay:[1,0],
            fileUri:'',
            fileData:'',
            isPay:false,
            serviceFee: [],
            totalServiceFee:0,
            ownerInfo:{}
        });

    }

    _viewTimeComponent(){

    }

    componentWillReceiveProps(nextProps){
        let {send_address, receive_address} = this.props.order;

        if(nextProps.order.send_address != send_address){
            this.setState({
                send_address: nextProps.order.send_address,
                start_location: nextProps.order.send_location
            });
        }

        if(nextProps.order.receive_address != receive_address){
            this.setState({
                receive_address: nextProps.order.receive_address,
                dest_location: nextProps.order.receive_location
            });
        }

    }

    _uploadImage(){
        this.setState({
            disableUpload:true,
        })
        this._getObj();
    }

    async _getObj() {
        var options = {
            title: "上传照片",
            cancelButtonTitle: "取消",
            takePhotoButtonTitle: "拍照",
            chooseFromLibraryButtonTitle: "选择相册",
            permissionDenied: {
                title: "提示",
                text: "没有拍照和获取相册权限",
                reTryTitle: "重试",
                okTitle: "确定"
            },
            mediaType:"photo",
            quality: 0.8,
            maxHeight: parseInt(deviceHeight*2),
            maxWidth: parseInt(deviceWidth*2),
            storageOptions: {
                skipBackup: true,
                path: "images"
            }
        };
        // 照片
        ImagePicker.showImagePicker(options, response => {
            this.setState({
                disableUpload:false,
            })
            // Same code as in above section!
            console.log('test======response',JSON.stringify(response));
            if (response.error) {
                console.log("ImagePicker Error: ", response.error);
            } else {
                if (response.didCancel) {
                    console.log("User cancelled image picker");
                    return;
                }
                console.log('test0000000000',response.uri);
                let fileData = "data:image/jpeg;base64," + response.data;
                this._completeUpload(response.uri,fileData);
            }
        });

        return false;
    }

    _completeUpload(fileUri,fileData){
        this.setState({
            fileUri:fileUri,
            fileData:fileData,
        });
    }
    _clearImage(){
        this.setState({
            fileUri:'',
            fileData:'',
        })
    }


    _selectAction(index){
        let temp = [0,0];
        temp[index] = 1;
        this.setState({ activeServiceWay:temp });
    }

    async _getNonPayment(){

        if (this.props.showTimes == 0) {//没有展示过

            let {source, data} = this.props;

            let {date, send_phone, receive_phone, obj_name, remarks, send_address, receive_address} = this.state;
            let req_data = {
                from_address: send_address,
                to_address: receive_address,
                service_time: date||(source=='edit'?data.service_time:''),
                obj_name: obj_name||(source=='edit'?data.obj_name:''),
                phone: receive_phone||(source=='edit'?data.phone:''),
                user_phone: send_phone,
                remarks: remarks,
            };

            if(!req_data.user_phone){
                this.refs.toast.show('请输入发件人手机号码');
                return;
            }
            if(!req_data.phone){
                this.refs.toast.show('请输入收件人手机号码');
                return;
            }

            if(!/^1[0-9]{10}$/.test(req_data.user_phone)){
                this.refs.toast.show('请输入正确的发件人手机号码');
                return;
            }

            if(!/^1[0-9]{10}$/.test(req_data.phone)){
                this.refs.toast.show('请输入正确的收件人手机号码');
                return;
            }

            if(!req_data.from_address){
                this.refs.toast.show('请输入寄出地址');
                return;
            }
            if(!req_data.to_address){
                this.refs.toast.show('请输入收货地址');
                return;
            }

            if(!req_data.obj_name){
                this.refs.toast.show('请输入物品名称');
                return;
            }

            if(req_data.obj_name.length>100){
                this.refs.toast.show('物品名称不能超过100个字符');
                return;
            }

            if(moment(req_data.service_time)-moment()<0){
                this.refs.toast.show('输入的时间需大于当前时间');
                return;
            }

            if(req_data.remarks.length>200){
                this.refs.toast.show('备注信息不能超过200个字符');
                return;
            }


            this.setState({loadingShow:true});
            let result = await api.post('/order/getNonPaymentOrder',{phone:send_phone});
            console.log('_getNonPayment',result);
            if (result.cd != 0) {
                Toast.bottom(result.msg);
                return;
            }
            if (result.data && result.data.length != 0) {//有欠费

                this.setState({loadingShow:false},() => {
                    let orderArrearageInfo = result.data[0];
                    this.props.onShowPayNotifyDialog(send_phone,orderArrearageInfo,result.data.length);
                });
                

            }else{//没有欠费
                this.setState({loadingShow:false},() => {
                    this._submitAction();
                });
            }
        }else{
            this.setState({loadingShow:false},() => {
                this._submitAction();
            });
        }
        


    }

    _clickImage(index){
        let {fileUri} = this.state;
        if (fileUri) {//有图片则预览
            this._previewPicture(fileUri)
            return;
        }
    }

    _previewPicture(fileUri){
        Navigation.startPreviewPictureActivity({"currentIndex":0,"fileUris":fileUri,"isUrl":true})
    }

    onChangeTextMoney(value,item,index){
        var {serviceFee} = this.state
        let serviceFeeCopy = [];
        var totalServiceFee = 0;
        value = value.replace(/[^\d.]/g,"");  
        value = value.replace(/\.{2,}/g,".");   
        value = value.replace(".","$#$").replace(/\./g,"").replace("$#$","."); 
        value = value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3'); 
        if(value.indexOf(".")< 0 && value !=""){
            value= parseFloat(value); 
        } 

        if (value == '') {

            item.fee = 0;
            console.log('onChangeText',serviceFee);
            totalServiceFee = 0;
            for (var i = 0; i < serviceFee.length; i++) {
                totalServiceFee += parseFloat(serviceFee[i].fee)
            }
            console.log('onChangeText=test',totalServiceFee);
            this.setState({
                totalServiceFee,
                serviceFee,
            })
            return;

        }
        item = {...item,fee:value};
        for (var i = 0; i < index; i++) {
            serviceFeeCopy.push(serviceFee[i]);
        }
        serviceFeeCopy.push(item);
        for (var i = index + 1; i < serviceFee.length; i++) {
            serviceFeeCopy.push(serviceFee[i]);
        }
        console.log('onChangeText',item);
        console.log('onChangeText',serviceFeeCopy);
        totalServiceFee = 0;
        for (var i = 0; i < serviceFeeCopy.length; i++) {
            totalServiceFee += parseFloat(serviceFeeCopy[i].fee)
        }
        console.log('onChangeText=test',totalServiceFee);
        this.setState({
            totalServiceFee,
            serviceFee:serviceFeeCopy,
        })
            
    }

    render() {
        let {data, source} = this.props;
        let {send_address, receive_address,isPay,serviceFee,ownerInfo,totalServiceFee} = this.state;

        let Sview = Platform.OS=="ios"?KeyboardAwareScrollView:ScrollView;
        return (
            <View style={styles.sendWrapper} pointerEvents={"box-none"} onStartShouldSetResponderCapture={(e) => {
                const focusField = TextInput.State.currentlyFocusedField();
                if (focusField != null && e.nativeEvent.target != focusField){
                    dismissKeyboard();
                }
            }}>
                <Sview
                    style={styles.container}
                    keyboardShouldPersistTaps={'always'}
                    extraScrollHeight={60}
                    >
                    {
                        ownerInfo && ownerInfo.isVip == 1 && isPay?
                            <View style={{height: 40,backgroundColor:'#FFFCED',borderBottomWidth:0.5,borderColor:'#E8E8E8',flexDirection:'row',paddingLeft:15,alignItems:'center'}}>
                                <Text style={{color:'#333333',fontSize:13}}>
                                    服务费用
                                    <Text style={{color:'#FF8200'}}>¥{parseFloat(totalServiceFee).toFixed(2)}</Text>
                                    ，VIP会员每月免费
                                    <Text style={{color:'#FF8200'}}>15</Text>
                                    次，本月剩余
                                    <Text style={{color:'#FF8200'}}>{ownerInfo.keeperServiceLeftCount}</Text>
                                    次
                                </Text>
                                
                            </View>
                        :
                            null
                    }
                    <View style={styles.formContainer}>
                        <View style={styles.formItem}>
                            <Text style={styles.leftText}>发件人</Text>
                            <TextInput
                                value={this.state.send_phone}
                                style={[styles.itemRight, source=='edit'?{color:"#B5B5B5"}:{}]}
                                editable = {source=='edit'?false:true}
                                clearButtonMode={'while-editing'}
                                maxLength={13}
                                smartScrollOptions = {{
                                    moveToNext: true,
                                    type:'text'
                                }}
                                keyboardType={'phone-pad'}
                                underlineColorAndroid={'#ffffff'}
                                placeholder={'请输入发件人手机号'}
                                onChangeText={(text)=>{
                                    let p = text.replace(/ /g, '').substring(0,11);
                                    this.setState({send_phone: p, addrContent:false,roomInfo: false, roomLocation: false});
                                    if(p.length == 11){
                                        this._showUserAddrBtn(p);
                                        if (this.state.date) {
                                            this._getServiceFeeInfo(p,this.state.date);
                                        }
                                    }
                                }}
                                placeholderTextColor={'#B5B5B5'}
                            />
                        </View>
                        <View style={[styles.formItem,{borderBottomWidth:0}]}>
                            <Text style={styles.leftText}>收件人</Text>
                            <TextInput
                                value={this.state.receive_phone}
                                defaultValue={source=='edit'?data.phone:''}
                                style={styles.itemRight}
                                editable = {true}
                                clearButtonMode={'while-editing'}
                                maxLength={13}
                                smartScrollOptions = {{
                                    moveToNext: true,
                                    type:'text'
                                }}
                                keyboardType={'phone-pad'}
                                underlineColorAndroid={'#ffffff'}
                                placeholder={'请输入收件人手机号'}
                                onChangeText={(text)=>{this.setState({receive_phone:text.replace(/ /g, '').substring(0,11)})}}
                                placeholderTextColor={'#B5B5B5'}
                            />
                        </View>
                    </View>
                    <View style={styles.addressContainer}>
                        <Touch onPress={this._addAddress.bind(this, 'send')} style={styles.addressBtn}>
                            <Image source={require('../../../img/hk_send_icon.png')} style={styles.leftImage}/>
                            <TextInput
                                value={send_address}
                                style={styles.centerAddress}
                                editable={false}
                                multiline={Platform.OS=='ios'?false:true}
                                underlineColorAndroid={'#ffffff'}
                                placeholder={'请输入寄出地址'}
                                placeholderTextColor={'#B5B5B5'}
                            />
                            <Image source={require('../../../img/hk_arrow_icon.png')} style={styles.rightImage}/>
                        </Touch>

                        <Touch onPress={this._addAddress.bind(this, 'receive')} style={styles.addressBtn}>
                            <Image source={require('../../../img/hk_receive_icon.png')} style={styles.leftImage}/>
                            <TextInput
                                value={receive_address}
                                style={styles.centerAddress}
                                editable = {false}
                                multiline={Platform.OS=='ios'?false:true}
                                underlineColorAndroid={'#ffffff'}
                                placeholder={'请输入收货地址'}
                                placeholderTextColor={'#B5B5B5'}
                            />
                            <Image source={require('../../../img/hk_arrow_icon.png')} style={styles.rightImage}/>
                        </Touch>

                        <TouchableOpacity style={[styles.addressBtnTime,{borderBottomWidth: StyleSheet.hairlineWidth,borderColor: '#DDDDDD'}]}>
                            <Text style={styles.leftText}>取件时间</Text>
                            <DatePicker
                                style={styles.centeDate}
                                date={this.state.date}
                                mode="datetime"
                                format="YYYY-MM-DD HH:mm"
                                minDate={moment().format('YYYY-MM-DD HH:mm')}
                                // maxDate="2016-06-01"
                                confirmBtnText="确定"
                                cancelBtnText="关闭"
                                showIcon={false}
                                customStyles={{
                                  dateInput: {
                                    marginLeft: 0,
                                    alignItems: 'flex-start',
                                    borderWidth:0,
                                    },
                                  dateText:{
                                    textAlign: 'left',
                                },
                                btnTextCancel:{
                                    color: '#7B7B7B',
                                    fontSize: 15,
                                },
                                btnTextConfirm:{
                                    color: '#EA5404',
                                    fontSize:15
                                },
                                datePicker:{
                                    borderTopColor: '#DDDDDD',
                                    backgroundColor: '#fff',
                                },
                                datePickerCon:{
                                    backgroundColor: '#f3f3f3',
                                }
                                }}
                                onDateChange={(date) => {
                                    this.setState({date: date})
                                    if (this.state.send_phone && this.state.send_phone.length == 11) {
                                        this._getServiceFeeInfo(this.state.send_phone,date)
                                    }
                                }}
                              />
                            <Image source={require('../../../img/hk_arrow_icon.png')} style={styles.rightImage}/>
                        </TouchableOpacity>


                        
                        {
                            isPay && serviceFee && serviceFee.length > 0?
                            serviceFee.map((item,index) =>{
                                return (<TouchableOpacity key={index} style={[styles.addressBtnTime,{borderBottomWidth: StyleSheet.hairlineWidth,
        borderColor: '#DDDDDD'}]} onPress={this._serviceFeeExplain.bind(this,item)}>
                                    <Text style={styles.leftText}>{item.serviceFeeName}</Text>

                                    {
                                        item.feeModifiable == 1?
                                            <View
                                                style={{flex:1,flexDirection:'row',alignItems:'center',marginLeft: 15}} 
                                            >
                                                <Text style={{color:'#000000',fontSize:15}}>¥</Text>
                                                <TextInput 
                                                    style={{color:'#000000',fontSize:15,flex:1,marginLeft: -3}}
                                                    underlineColorAndroid={'#ffffff'} 
                                                    value={`${item.fee}`}
                                                    clearButtonMode={'while-editing'}
                                                    keyboardType={'numeric'}
                                                    maxLength={10}
                                                    onChangeText={(value)=>{this.onChangeTextMoney(value,item,index)}}/>
                                            </View>
                                        :
                                            <Text style={styles.itemRight}>¥{parseFloat(item.fee).toFixed(2)}</Text>
                                    }

                                    <Text style={styles.nightFeeInstruction}>费用说明</Text>
                                    <Image source={require('../../../img/hk_arrow_icon.png')} style={styles.rightImage}/>
                                </TouchableOpacity>)
                            })
                            :
                            null
                        }
                        

                    </View>
                    <View style={styles.formContainer}>
                        <View style={styles.formItem}>
                            <Text style={styles.leftText}>物品名称</Text>
                            <TextInput
                                value={this.state.obj_name}
                                defaultValue={source=='edit'?data.obj_name:''}
                                style={styles.itemRight}
                                editable={true}
                                multiline={Platform.OS=='ios'?false:true}
                                numberOfLines={1}
                                clearButtonMode={'while-editing'}
                                smartScrollOptions = {{
                                    moveToNext: true,
                                    type:'text',
                                    scrollRef:'scroll'
                                }}
                                onChangeText={(text)=>{this.setState({obj_name:text})}}
                                underlineColorAndroid={'#ffffff'}
                                placeholder={'请输入物品名称'}
                                placeholderTextColor={'#B5B5B5'}
                            />
                        </View>
                        <View style={[styles.formItemRemark,{borderBottomWidth:0}]}>
                            <Text style={[styles.leftText,{marginTop:10}]}>备注信息</Text>
                            <TextInput
                                value={this.state.remarks}
                                defaultValue={source=='edit'?data.remarks:''}
                                style={[styles.itemRight,{height:88}]}
                                editable = {true}
                                multiline={Platform.OS=='ios'?false:true}
                                numberOfLines={4}
                                clearButtonMode={'while-editing'}
                                smartScrollOptions = {{
                                    moveToNext: true,
                                    type:'text',
                                    scrollRef:'scroll'
                                }}
                                underlineColorAndroid={'#ffffff'}
                                onChangeText={(text)=>{this.setState({remarks:text})}}
                                placeholder={'选填，如重量等'}
                                placeholderTextColor={'#B5B5B5'}
                                textAlignVertical={'top'} 
                            />
                            <TouchableOpacity
                                accessible={true}
                                activeOpacity={0.7}
                                onPress={ this._uploadImage.bind(this)}
                                disabled={this.state.disableUpload}
                            >
                                <Text
                                 style={[styles.actionBtn,{marginRight:10,marginTop:12}]}
                                >
                                    上传图片
                                </Text>
                            </TouchableOpacity>
                        </View>
                        {
                            this.state.fileUri?
                                <View style={styles.imageContanier}>
                                    <View style={styles.clearImageContainer}>
                                        <TouchableOpacity activeOpacity={0.7} onPress={this._clearImage.bind(this)} style={{height:30,height:30}}>
                                            <Image source={require('../../../img/close_icon.png')}  style={{marginRight:15,width:15,height:15}}/>
                                        </TouchableOpacity>
                                    </View>
                                    <TouchableOpacity activeOpacity={0.7} onPress={this._clickImage.bind(this)}>
                                        <Image source={{uri: this.state.fileUri}} resizeMode="contain" style={[styles.uploadAvatar,{marginTop:-7}]}/>
                                    </TouchableOpacity>
                                </View>
                            :
                            null
                        }
                    </View>

                    <View style={[styles.formContainer,{marginBottom:23}]}>
                        <View style={[styles.formItem,{borderBottomWidth:0}]}>
                            <Text style={styles.leftText}>服务方式</Text>
                            <View style={[styles.selectContent, {marginLeft:15,marginTop:0}]}>
                                <TouchableOpacity activeOpacity={0.7} onPress={this._selectAction.bind(this,0)} style={styles.selectBtn}>
                                    <Text style={this.state.activeServiceWay[0]?styles.activeText:styles.notActiveText}>管家服务</Text>
                                </TouchableOpacity>
                                <TouchableOpacity activeOpacity={0.7} onPress={this._selectAction.bind(this,1)} style={styles.selectBtn}>
                                    <Text style={this.state.activeServiceWay[1]?styles.activeText:styles.notActiveText}>第三方平台服务</Text>
                                </TouchableOpacity>
                            </View>
                        </View>
                    </View>

                </Sview>
                <View style={styles.submitBtnContainer}>
                    <Touch onPress={this._getNonPayment.bind(this)} style={styles.submitBtn}>
                        <Text style={styles.submitBtnText}>确定</Text>
                    </Touch>
                </View>
                <ToastTip ref="toast" offsetY={160}/>
                <LoadingTip show={this.state.loadingShow}/>
            </View>
        );
    }
}

var connectHelper = require('../../services/connectHelper');
EditSendOrder = connectHelper(state => state)(EditSendOrder);

module.exports = EditSendOrder;
